<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Introduction - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.config.introduction.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.config.introduction.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.config.html">Zend_Config</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.config.html">Zend_Config</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.config.theory_of_operation.html">Theory of Operation</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.config.introduction" class="section"><div class="info"><h1 class="title">Introduction</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Config</span> is designed to simplify the access to, and the use of,
        configuration data within applications. It provides a nested object property based user
        interface for accessing this configuration data within application code. The configuration
        data may come from a variety of media supporting hierarchical data storage. Currently
        <span class="classname">Zend_Config</span> provides adapters for configuration data that are stored
        in text files with <a href="zend.config.adapters.ini.html" class="link"><span class="classname">Zend_Config_Ini</span></a> and
        <a href="zend.config.adapters.xml.html" class="link"><span class="classname">Zend_Config_Xml</span></a>.
    </p>

    <div class="example" id="zend.config.introduction.example.using"><div class="info"><p><b>Example #1 Using Zend_Config</b></p></div>
        

        <div class="example-contents"><p>
            Normally it is expected that users would use one of the adapter classes such as <a href="zend.config.adapters.ini.html" class="link"><span class="classname">Zend_Config_Ini</span></a> or
            <a href="zend.config.adapters.xml.html" class="link"><span class="classname">Zend_Config_Xml</span></a>,
            but if configuration data are available in a <acronym class="acronym">PHP</acronym> array, one may
            simply pass the data to the <span class="classname">Zend_Config</span> constructor in order to
            utilize a simple object-oriented interface:
        </p></div>

        <pre class="programlisting brush: php">
// Given an array of configuration data
$configArray = array(
    &#039;webhost&#039;  =&gt; &#039;www.example.com&#039;,
    &#039;database&#039; =&gt; array(
        &#039;adapter&#039; =&gt; &#039;pdo_mysql&#039;,
        &#039;params&#039;  =&gt; array(
            &#039;host&#039;     =&gt; &#039;db.example.com&#039;,
            &#039;username&#039; =&gt; &#039;dbuser&#039;,
            &#039;password&#039; =&gt; &#039;secret&#039;,
            &#039;dbname&#039;   =&gt; &#039;mydatabase&#039;
        )
    )
);

// Create the object-oriented wrapper upon the configuration data
$config = new Zend_Config($configArray);

// Print a configuration datum (results in &#039;www.example.com&#039;)
echo $config-&gt;webhost;

// Use the configuration data to connect to the database
$db = Zend_Db::factory($config-&gt;database-&gt;adapter,
                       $config-&gt;database-&gt;params-&gt;toArray());

// Alternative usage: simply pass the Zend_Config object.
// The Zend_Db factory knows how to interpret it.
$db = Zend_Db::factory($config-&gt;database);
</pre>

    </div>

    <p class="para">
        As illustrated in the example above, <span class="classname">Zend_Config</span> provides nested
        object property syntax to access configuration data passed to its constructor.
    </p>

    <p class="para">
        Along with the object oriented access to the data values,
        <span class="classname">Zend_Config</span> also has  <span class="methodname">get()</span> which will
        return the supplied default value if the data element doesn&#039;t exist. For example:
    </p>

    <pre class="programlisting brush: php">
$host = $config-&gt;database-&gt;get(&#039;host&#039;, &#039;localhost&#039;);
</pre>


    <div class="example" id="zend.config.introduction.example.file.php"><div class="info"><p><b>Example #2 Using Zend_Config with a PHP Configuration File</b></p></div>
        

        <div class="example-contents"><p>
            It is often desirable to use a pure <acronym class="acronym">PHP</acronym>-based configuration file.
            The following code illustrates how easily this can be accomplished:
        </p></div>

        <pre class="programlisting brush: php">
// config.php
return array(
    &#039;webhost&#039;  =&gt; &#039;www.example.com&#039;,
    &#039;database&#039; =&gt; array(
        &#039;adapter&#039; =&gt; &#039;pdo_mysql&#039;,
        &#039;params&#039;  =&gt; array(
            &#039;host&#039;     =&gt; &#039;db.example.com&#039;,
            &#039;username&#039; =&gt; &#039;dbuser&#039;,
            &#039;password&#039; =&gt; &#039;secret&#039;,
            &#039;dbname&#039;   =&gt; &#039;mydatabase&#039;
        )
    )
);
</pre>


        <pre class="programlisting brush: php">
// Configuration consumption
$config = new Zend_Config(require &#039;config.php&#039;);

// Print a configuration datum (results in &#039;www.example.com&#039;)
echo $config-&gt;webhost;
</pre>

    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.config.html">Zend_Config</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.config.html">Zend_Config</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.config.theory_of_operation.html">Theory of Operation</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.config.html">Zend_Config</a></li>
  <li class="active"><a href="zend.config.introduction.html">Introduction</a></li>
  <li><a href="zend.config.theory_of_operation.html">Theory of Operation</a></li>
  <li><a href="zend.config.adapters.ini.html">Zend_Config_Ini</a></li>
  <li><a href="zend.config.adapters.json.html">Zend_Config_Json</a></li>
  <li><a href="zend.config.adapters.xml.html">Zend_Config_Xml</a></li>
  <li><a href="zend.config.adapters.yaml.html">Zend_Config_Yaml</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>